#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import os
import sys
import yaml
import pandas as pd
from openpyxl import load_workbook

# 添加src目录到路径
current_dir = os.path.dirname(os.path.abspath(__file__))
src_dir = os.path.join(current_dir, 'src')
sys.path.insert(0, src_dir)

try:
    print("开始加载模块...")
    from template_engine import render_templates
    print("模块加载成功")

    # 加载配置
    config_path = os.path.join(src_dir, 'config.yml')
    print(f"读取配置文件: {config_path}")
    
    with open(config_path, 'r', encoding='utf-8') as file:
        config = yaml.safe_load(file)
    print("配置文件读取成功")

    # 测试简单的模板渲染
    test_columns = [
        {'列名': 'test_column', '注解': '测试列', 'java类型': 'String', '查询方式': 'LIKE'}
    ]
    
    print("开始测试模板渲染...")
    result = render_templates(
        config=config,
        db_model='test_db',
        table_name='test_table', 
        table_comm='测试表',
        columns=test_columns,
        script_dir=src_dir,
        verbose=True,
        package_name='com.test'
    )
    print(f"测试完成，生成文件数: {len(result)}")

except Exception as e:
    print(f"发生错误: {e}")
    import traceback
    traceback.print_exc()